package com.boot.redis;

import org.redisson.Redisson;
import org.redisson.api.*;
import org.redisson.config.Config;

import java.util.concurrent.TimeUnit;

/**
 * @Package com.boot.redis
 */
public class RedisTester {

    public static void main(String[] args) {

        Config config = new Config();
        config.useClusterServers()
                // use "rediss://" for SSL connection
                .addNodeAddress("redis://127.0.0.1:6379");

        // Sync and Async API
        RedissonClient redisson = Redisson.create(config);

        RLock lock = redisson.getLock("mylock");
        lock.lock(1000, TimeUnit.MICROSECONDS);
        lock.tryLock();

        // Reactive API
        RedissonReactiveClient redissonReactive = redisson.reactive();

        // RxJava3 API
        RedissonRxClient redissonRx = redisson.rxJava();

        RBloomFilter<Integer> bloomFilter = redisson.getBloomFilter("bloomFilter");
        //初始化布隆过滤器：预计元素为100000000L,误差率为3%
        bloomFilter.tryInit(100000000L,0.03);
        bloomFilter.add(1);
        bloomFilter.contains(1);

        RRateLimiter rateLimiter = redisson.getRateLimiter("rateLimiter");
//        rateLimiter.setRate();

    }
}
